using System;
using System.Collections.Generic;

using BLToolkit.DataAccess;

namespace EMan.DAL.Firebird
{
  public abstract class Dalc< T > : DataAccessor< T >, IDisposable
  {
    private readonly Dictionary< string, string > _actionName2SpPostfix = 
      new Dictionary< string, string >
        {
          {"Get", "selbykey"},
          {"Insert", "ins"},
          {"Update", "upd"},
          {"InsertOrUpdate", "iu"},
          {"Delete", "del"},
          {"GetList", "sel"}
        };

    protected override string GetDefaultSpName( string typeName, string actionName )
    {
      string spPostfix;
      if( ! _actionName2SpPostfix.TryGetValue( actionName, out spPostfix ) )
      {
        var exc = new ArgumentException( "Unknown action name", "actionName" );
        exc.Data.Add( "typeName", typeName );
        exc.Data.Add( "ActionName", actionName );
        throw exc;
      }
      return typeName + "_" + spPostfix;
    }

    public void Dispose()
    {
      DbManager.Dispose();
    }
  }
}